package br.com.j7.jdesk.persistence.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * 
 * 
 * 
 * @author Edivando Alves
 *
 */
@Entity
@NamedQueries({ @NamedQuery(name="serviceLog", query="Select sl from ServicesLogs sl" ),
				@NamedQuery(name="serviceLogByService", query="Select sl from ServicesLogs sl Where sl.service = ?1 order by 1")})
public class ServicesLogs implements Serializable{

	private static final long serialVersionUID = 1L;
	
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private Integer idServiceLog;
	
	@ManyToOne
	@JoinColumn(name="idService")
	private Services service;
	@Temporal(TemporalType.TIMESTAMP)
	private Date dtBegin;
	@Temporal(TemporalType.TIMESTAMP)
	private Date dtEnd;
	@OneToMany(mappedBy="serviceLog", cascade=CascadeType.REMOVE)
	private List<ServicesAnnotations> serviceAnnotation;
	@ManyToOne
	@JoinColumn( name="idServiceSituation" )
	private ServicesSituations serviceSituation;
	@ManyToOne
	@JoinColumn(name="idUser")
	private Users user;
	
	public ServicesLogs() {
	}

	public Integer getIdServiceLog() {
		return idServiceLog;
	}

	public void setIdServiceLog(Integer idServiceLog) {
		this.idServiceLog = idServiceLog;
	}

	public Services getService() {
		return service;
	}

	public void setService(Services service) {
		this.service = service;
	}

	public Date getDtBegin() {
		return dtBegin;
	}

	public void setDtBegin(Date dtBegin) {
		this.dtBegin = dtBegin;
	}

	public Date getDtEnd() {
		return dtEnd;
	}

	public void setDtEnd(Date dtEnd) {
		this.dtEnd = dtEnd;
	}

	public List<ServicesAnnotations> getServiceAnnotation() {
		return serviceAnnotation;
	}
	
	public void setServiceAnnotation(List<ServicesAnnotations> serviceAnnotation) {
		if( serviceAnnotation == null ){
			serviceAnnotation = new ArrayList<>();
		}
		this.serviceAnnotation = serviceAnnotation;
	}
	
	public void addServiceAnnotation( ServicesAnnotations serviceAnnotation ){
		if( this.serviceAnnotation == null ){
			this.serviceAnnotation = new ArrayList<>();
		}
		this.serviceAnnotation.add(serviceAnnotation);		
	}
	
	public Users getUser() {
		if( user == null )
			user = new Users();
		return user;
	}
	
	public void setUser(Users user) {
		this.user = user;
	}
	
	public ServicesSituations getServiceSituation() {
		if( serviceSituation == null ){
			serviceSituation = new ServicesSituations();
		}
		return serviceSituation;
	}
	
	public void setServiceSituation(ServicesSituations serviceSituation) {
		this.serviceSituation = serviceSituation;
	}
	
	@Override
	public int hashCode() {
		return idServiceLog;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ServicesLogs other = (ServicesLogs) obj;
		if (idServiceLog == null) {
			if (other.idServiceLog != null)
				return false;
		} else if (!idServiceLog.equals(other.idServiceLog))
			return false;
		return true;
	}
	
	
	
	

}
